(function($, window, document){
  'use strict';

	$(function() {
		$(document).on('change', "[check-all]", function(){
			var target = $(this).attr('target');
			$(target).prop('checked', this.checked);
		});

	  	$('input[data-toogle="onchange"]').change(function(){
			var $this = $(this),
		        target = $this.data('target'),
		        value = $this.data('value');
			$(target).collapse('toggle');
		});
	});

	var Selector = 'th.check-all';

  	$(Selector).on('change', function() {
		//console.log($(this));
	    var $this = $(this),
	        index= $this.index() + 1,
	        checkbox = $this.find('input[type="checkbox"]'),
	        table = $this.parents('table');
	    // Make sure to affect only the correct checkbox column
	    table.find('tbody > tr > td:nth-child('+index+') input[type="checkbox"]').prop('checked', checkbox[0].checked);
  	});

}(jQuery, window, document));